﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HouseAgencySite.Models;

namespace HouseAgencySite.Utils
{
    public static class ParamHelper
    {
        /// <summary>
        /// 户型
        /// </summary>
        /// <param name="Search"></param>
        /// <param name="selectedValue"></param>
        /// <returns></returns>
        public static List<SelectListItem> HuXing(bool Search = false, string selectedValue = "")
        {

            List<SelectListItem> huXingList = new List<SelectListItem>();
            SelectListItem item = new SelectListItem();
            if (Search)
            {
                item.Value = "0";
                item.Text = "全部";
                huXingList.Add(item);
            }

            huXingList.AddRange(new List<SelectListItem>()
                {                   
                    new SelectListItem(){ Value="1",Text="单间",Selected=selectedValue=="1"},
                    new SelectListItem(){ Value="2",Text="一居室",Selected=selectedValue=="2"},
                     new SelectListItem(){ Value="3",Text="一室一厅",Selected=selectedValue=="3"},
                      new SelectListItem(){ Value="4",Text="两室一厅",Selected=selectedValue=="4"},
                       new SelectListItem(){ Value="5",Text="三室一厅",Selected=selectedValue=="5"},
                        new SelectListItem(){ Value="6",Text="三室两厅",Selected=selectedValue=="6"},
                         new SelectListItem(){ Value="8",Text="两居",Selected=selectedValue=="8"},
                          new SelectListItem(){ Value="9",Text="三居",Selected=selectedValue=="9"},
                           new SelectListItem(){ Value="10",Text="合租",Selected=selectedValue=="10"},
                         new SelectListItem(){ Value="7",Text="其他",Selected=selectedValue=="7"}
                });
            return huXingList;
        }
        /// <summary>
        /// 房屋类型
        /// </summary>
        /// <param name="Search"></param>
        /// <param name="selectedValue"></param>
        /// <returns></returns>
        public static List<SelectListItem> HouseType(bool Search = false, string selectedValue = "")
        {

            List<SelectListItem> houseType = new List<SelectListItem>();
            SelectListItem item = new SelectListItem();
            if (Search)
            {
                item.Value = "0";
                item.Text = "全部";
                houseType.Add(item);
            }
            houseType.AddRange(new List<SelectListItem>()
                {                   
                    new SelectListItem(){ Value="1",Text="出租",Selected=selectedValue=="1"},
                    new SelectListItem(){ Value="2",Text="出售",Selected=selectedValue=="2"},
                     new SelectListItem(){ Value="3",Text="写字楼",Selected=selectedValue=="3"},
                      new SelectListItem(){ Value="4",Text="底商",Selected=selectedValue=="4"}
                });
            return houseType;
        }
        /// <summary>
        /// 地区
        /// </summary>
        /// <param name="type"></param>
        /// <param name="areaName"></param>
        /// <param name="selectedItem"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public static List<SelectListItem> Areas(int type = 0, string areaName = "", string selectedItem = "", bool search=false)
        {
            AgencyDBContext db = new AgencyDBContext();
            var areas = db.Areas.Where(o=>o.IsDelete==false).ToList();

            List<SelectListItem> list = new List<SelectListItem>();
            if (search)
            {
                list.Add(new SelectListItem() { Text = "全部", Value = "" });
            }
            if (type == 0)
            {
                var items = areas.Select(o => o.City).Distinct().ToList();
                foreach (var item in items)
                {
                    list.Add(new SelectListItem() { Selected = selectedItem == item, Value = item, Text = item });
                }
            }
            if (type == 1)
            {
                var items = areas.Where(o => o.City == areaName).Select(o => o.Area).Distinct().ToList();
                foreach (var item in items)
                {
                    list.Add(new SelectListItem() { Selected = selectedItem == item, Value = item, Text = item });
                }
            }
            if (type == 2)
            {
                var items = areas.Where(o => o.Area == areaName).Select(o => o.AddressName).Distinct().ToList();
                foreach (var item in items)
                {
                    list.Add(new SelectListItem() { Selected = selectedItem == item, Value = item, Text = item });
                }
            }
            return list;

        }
        /// <summary>
        /// 用户类型
        /// </summary>
        /// <param name="selValue"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public static List<SelectListItem> UserType(string selValue="", bool search=false) {
            List<SelectListItem> list = new List<SelectListItem>();
            if (search)
            {
                list.Add(new SelectListItem() { Value = "", Text = "全部" });
            }
            list.Add(new SelectListItem() { Value = "0", Text = "管理员", Selected = selValue == "0" });
            list.Add(new SelectListItem() { Value = "1", Text = "业务员", Selected = selValue == "1" });
            return list;
        }
        /// <summary>
        ///描述内容类型
        /// </summary>
        /// <param name="selValue"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public static List<SelectListItem> HtmlContentType(string selValue = "", bool search = false)
        {
            List<SelectListItem> list = new List<SelectListItem>();
            if (search)
            {
                list.Add(new SelectListItem() { Value = "", Text = "全部" });
            }
            list.Add(new SelectListItem() { Value = "1", Text = "关于我们", Selected = selValue == "1" });
            list.Add(new SelectListItem() { Value = "2", Text = "贷款担保", Selected = selValue == "2" });
            list.Add(new SelectListItem() { Value = "3", Text = "招贤纳士", Selected = selValue == "3" });
            list.Add(new SelectListItem() { Value = "4", Text = "Banner图", Selected = selValue == "4" });
            list.Add(new SelectListItem() { Value = "5", Text = "企业文化", Selected = selValue == "5" });
            return list;
        }
        /// <summary>
        /// 获取地区
        /// </summary>
        /// <param name="selValue"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public static List<SelectListItem> GetHouseArea(string selValue = "", bool search = false)
        {
            List<SelectListItem> list = new List<SelectListItem>();
            if (search)
            {
                list.Add(new SelectListItem() { Value = "", Text = "全部" });
            }
            AgencyDBContext db = new AgencyDBContext();
            var areas = db.Areas.Select(o => new { Guid = o.Guid, FullPath = o.FullPath,IsDelete=o.IsDelete }).Where(o => o.IsDelete == false).ToList().OrderBy(o => o.FullPath);     
           foreach(var item in areas){
               list.Add(new SelectListItem() { Value =item.Guid, Text =item.FullPath, Selected = item.Guid==selValue });
           }
            return list;
        }

       

    }
}